<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var myObject = {
            a:2
        };
        // 当你想禁止一个对象添加新属性并且保留原有属性时 
        // 就可以使用Object.preventExtensions(obj)这个方法
        Object.preventExtensions( myObject );

        myObject.b = 3;
        console.log(myObject.b);
    </script>
</body>
</html>